#!/bin/bash

#判断是否存在密钥
if [ -f ~/.ssh/id_rsa ]; then
	rm -rf ~/.ssh/id_rsa*
fi

#生成密钥对
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P "" &> /dev/null

# 判断known_hosts文件中是否包含对方主机的密钥
> ~/.ssh/known_hosts

for i in 131 132; do
/usr/bin/expect << eof
set timeout 10
spawn ssh-copy-id root@192.168.11.$i
expect "(yes/no)?"
send "yes\n"
expect "password:"
send "123456\n" 
expect eof
eof
done

echo "-------------------------------------------"
#验证
for i in 131 132; do
	ssh root@192.168.11.$i hostname
done 

